#include<bits/stdc++.h>
using namespace std;

int n;
int T;
int a[100004];
int b[1000300];
int main()
{
   freopen("color.in","r",stdin);
   freopen("color.out","w",stdout);
     cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        if(n<=64)
        {

            int j=0;
            int ans=0;
            while(j<(1<<n))
            {
                int ans1=0;
                memset(b,0,sizeof(b));
                for(int i=0;i<n;i++)
                {
                    if((1<<i)&j)
                    {

                        b[i+1]=1;
                    }

                }
                for(int i=1;i<=n;i++)
                {

                    for(int k=i-1;k>=1;k--)
                    {

                        if(b[k]==b[i])
                        {
                            if(a[i]==a[k])
                            {

                                ans1+=a[i];
                            }
                            else break;
                        }
                    }
                }
                ans=max(ans,ans1);
                j++;
            }
            cout<<ans<<endl;
        }
        else{cout<<n<<endl;}
    }

    return 0;
}
